<template>
<div>
  <h1>当前求和为：{{sum}}</h1>
  <h2>当前求和数放大10倍后为：{{bigSum}}</h2>
  <h3>我在{{school}}学习{{subject}}</h3>
  <h3 style="color: red;">person组件的总人数为：{{personList.length}}</h3>
  <div class="event">
<!--    v-model.number强制转换为数字-->
    <select  class="same" v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button class="same" @click="increment(n)">+</button>
    <button class="same" @click="decrement(n)">-</button>
    <button class="same" @click="incrementOdd(n)">当前和为奇数再加</button>
    <button class="same" @click="incrementWait(n)">等一等再加</button>
  </div>
</div>
</template>

<script>
import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
    export default {
      name: "Calculation",
      data(){
          return{
            n:1, //用户选择的数字
          }
      },
      methods:{
        ...mapMutations({increment:"Addmore",decrement:"Deduce"}),
        ...mapActions({incrementOdd:"addOdd",incrementWait:"addWait"})
      },
      computed:{
        //借助mapState生成计算属性，从state中读取数据（对象写法）
        // ...mapState({he:"sum",xuexiao:"school",xueke:"subject"}),

        //借助mapState生成计算属性，从state中读取数据（数组写法）
        ...mapState(["sum","school","subject","personList"]),

        //借助mapGetters生成计算属性，从getters中读取数据（对象写法）
        // ...mapGetters({bigSum:'bigSum'})
        // 借助mapGetters生成计算属性，从getters中读取数据（数组写法）
        ...mapGetters(["bigSum"])
      },
      mounted() {
        // const x=mapState({he:"sum",xuexiao:"school",xueke:"subject"})
        const x=mapState(["sum","school","subject"])
        console.log(x)
      }
    }
</script>

<style scoped>
.event{
  display: flex;
  justify-content: space-between;
  width: 300px;
}
</style>
